/*
 * Created on 2007-12-29
 *
 * TODO 
 */
package jacky.lanlan.song.extension.struts.mock;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import jacky.lanlan.song.extension.struts.Scope;
import jacky.lanlan.song.extension.struts.action.ActionContext;
import jacky.lanlan.song.extension.struts.action.ValueStack;

/**
 * 委托MockValueStack，实现了 ValueStack 和 ActionContext ，其中 ValueStack 语意委托
 * {@link jacky.lanlan.song.extension.struts.action.MockValueStack} 实现；
 * ActionContext 委托外部注入的 Mock 实现。
 * @author Jacky.Song
 * @see jacky.lanlan.song.extension.struts.mock.MockValueStackTest
 */
public class DelegateMockValueStack implements ValueStack, ActionContext {
	
	private ValueStack mockVS = new MockValueStack();

	private ServletContext mockContext;
	private HttpServletRequest mockRequest;
	private HttpServletResponse mockResponse;
	private HttpSession mockSession;
	
	public void setMockContext(ServletContext mockContext) {
		this.mockContext = mockContext;
	}
	
	public void setMockRequest(HttpServletRequest mockRequest) {
		this.mockRequest = mockRequest;
	}
	
	public void setMockResponse(HttpServletResponse mockResponse) {
		this.mockResponse = mockResponse;
	}
	
	public void setMockSession(HttpSession mockSession) {
		this.mockSession = mockSession;
	}
	
	/* ValueStack */
	
	public String getRequestParameter(String name) {
		return mockVS.getRequestParameter(name);
	}
	
	public Object getAttribute(String name, Scope scope) {
		return mockVS.getAttribute(name, scope);
	}

	public Object getAttribute(String name) {
		return mockVS.getAttribute(name);
	}

	public void removeAttribute(String name, Scope scope) {
		mockVS.removeAttribute(name, scope);
	}

	public void setAttribute(String name, Object value, Scope scope) {
		mockVS.setAttribute(name,value,scope);
	}
	
	public void setAttribute(String name, Object value) {
		mockVS.setAttribute(name, value);
	}
	
	/* ActionContext */
	
	public ServletContext getContext() {
		return mockContext;
	}

	public HttpServletRequest getRequest() {
		return mockRequest;
	}

	public HttpServletResponse getResponse() {
		return mockResponse;
	}

	public HttpSession getSession() {
		return mockSession;
	}
}
